package com.kaishengit.interceptor;

import java.util.Map;
import java.util.Set;


import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.TextParseUtil;

public class LoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;
	private String sessionName;
	private String exclude;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Set<String> set = TextParseUtil.commaDelimitedStringToSet(exclude);
		if (set.contains(invocation.getProxy().getActionName())) {
			invocation.invoke();
		} else {
			Map<String, Object> session = invocation.getInvocationContext().getContext().getSession();
			if (session.get(sessionName) != null) {
				return invocation.invoke();
			}
		}
		return "validatefail";
	}

	public String getSessionName() {
		return sessionName;
	}

	public void setSessionName(String sessionName) {
		this.sessionName = sessionName;
	}

	public String getExclude() {
		return exclude;
	}

	public void setExclude(String exclude) {
		this.exclude = exclude;
	}

}
